package cn.chencaiju.day07;

import org.junit.Test;

public class StringBuilderTest {
	@Test
	public void testConcatenate() {
		StringBuilder sb = new StringBuilder();
		sb.insert(0, "The smaller the mind,");
		sb.append("the greater the conceit.");
		System.out.println(sb.toString());
	}

	public String Int2String(int number) {
		if (number == 0) {
			return "0";
		}
		String flag = "";
		if (number < 0) {
			flag = "-";
			number *= -1;
		}
		StringBuilder sb = new StringBuilder();
		while (number > 0) {
			sb.insert(0, number % 10);
			number /= 10;
		}
		sb.insert(0, flag);
		return sb.toString();

	}

	@Test
	public void testInteger2String() {
		for (int i = 0; i < 100; i++) {
			int number = (int) (Math.random() * 10000);
			if (number < 5000)
				number *= -1;
			System.out.println(number + "  " + Int2String(number));
		}
	}

}
